/**
 *
 * @author LiQun
 * @date 2019-07-26
 */
const fsExtra = require('fs-extra');
const fs = require('../../utils/fs');
const path = require('path');
const execa = require('execa');

/**
 * 初始化方法
 * @author LiQun
 * @date 2019-07-27
 * @param idePath 路径
 */
async function init(answers) {
  const idePath = answers['idePath'];
  if (!idePath) throw Error('请输入.ide文件路径')
  const data = fsExtra.readFileSync(idePath, 'utf-8')
  console.log('HTTP 服务端口号:', data);

  const loginResultOutput = answers['loginResultOutput']

  const initInfo = {
    ideFilePath: idePath,
    loginResultOutput
  }
  // 将端口号存储起来
  fsExtra.writeFileSync(path.resolve(__dirname, '../../cache/config.json'), JSON.stringify(initInfo, null, 2));
}

module.exports = init;

